package com.pocketsweet.ui.uilib;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;

import com.pocketsweet.service.UserService;

public class mySlideGalleryAdapter extends BaseAdapter {

	private Context context;
//	int i = 0;
	private ArrayList<MyImageView> imageViews = new ArrayList<MyImageView>();

	private List<String> mItems;

	public void setData(List<String> data) {
		this.mItems = data;
		notifyDataSetChanged();
	}

	public mySlideGalleryAdapter(Context context) {
		this.context = context;
	}

	@Override
	public int getCount() {
		return mItems != null ? mItems.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return mItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("deprecation")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		MyImageView view = new MyImageView(context);
		view.setLayoutParams(new Gallery.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		String item = mItems.get(position);
		// if (mlUser != null) {
		// Bitmap bmp;
		// bmp = ImageLoader.getInstance().loadImageSync(mlUser);
		// view.setTag(mlUser);
		// if (bmp != null) {
		// view.setImageBitmap(bmp);
		// }
		UserService.displayBgImage(item, view);
		// Log.e("==jia","i="+i);
		// i++;
		if (!this.imageViews.contains(view)) {
			imageViews.add(view);
		}
		// }
		return view;
	}

}
